package com.androidtv.pos.controller;

import com.androidtv.pos.modelbean.HomeArticleData;

import java.util.ArrayList;
import java.util.List;

public class CurrentMealController {


    private List<onMealClickListener> listeners = new ArrayList<>();
    private static CurrentMealController instance;

    private CurrentMealController() {
    }

    public static synchronized CurrentMealController getInstance() {
        if (instance == null) {
            instance = new CurrentMealController();
        }
        return instance;
    }


    public interface onMealClickListener {
        void onAddClick(HomeArticleData data);

        void onMinusClick(HomeArticleData data);
    }


    public void registerListener(onMealClickListener listener) {
        if (listeners != null && !listeners.contains(listener)) {
            listeners.add(listener);
        }
    }

    public void unregisterListener(onMealClickListener listener) {
        if (listeners != null && !listeners.contains(listener)) {
            listeners.remove(listener);
        }
    }

    public void notifyAccountChange(HomeArticleData addData, HomeArticleData minusData) {

        for (onMealClickListener clickListener : listeners) {
            if (addData != null) {
                clickListener.onAddClick(addData);
            }
            if (minusData != null) {
                clickListener.onMinusClick(minusData);
            }
        }
    }


}
